/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ace.game.entity.weapon;

import ace.system.Utilities;
import ace.system.xml.XmlNode;
import ace.system.xml.XmlReaderWriter;
import java.util.Hashtable;

/**
 *
 * @author Hallucinogen
 */
public class WeaponFactory {
	private WeaponFactory() {
		mWeaponDictionary = new Hashtable();
		XmlNode XML = XmlReaderWriter.getInstance().readFromXmlFile(Utilities.WEAPON_FILE);

		//For each child
		for (int i = 0; i < XML.getChildren().size(); i++) {
			//Get child
			XmlNode Child = (XmlNode)XML.getChildren().elementAt(i);

			//Check name
			if (Child.getNodeName().equals("weapon")) {
				//Prepare variable
				int j		= 0;
				int Index		= Integer.parseInt(Child.getAttribute("index"));

				//Save to dictionary
				if (Index >= 0) mWeaponDictionary.put(new Integer(Index), new WeaponData(Child));
			}
		}
	}

	public static WeaponFactory instance() {
		if (sInstance == null) {
			sInstance = new WeaponFactory();
		}
		return sInstance;
	}

	public WeaponData getWeaponData(int index) {
		return (WeaponData)mWeaponDictionary.get(new Integer(index));
	}

	private Hashtable mWeaponDictionary;

	// singleton
	private static WeaponFactory sInstance = null;
}
